import machine
import utime as time
from machine import ADC
import _thread 
import app_mqtt



ai1 = ADC(machine.Pin(1)) #ai1
ai1.atten(ADC.ATTN_0DB)  #使用0衰减，精度最高，输入电压范围：0-950mv
ai2 = ADC(machine.Pin(11)) #ai2
ai2.atten(ADC.ATTN_0DB)
DI1 = machine.Pin(42, machine.Pin.IN)
DI2 = machine.Pin(41, machine.Pin.IN)



uart = machine.UART(2, baudrate=115200) #2表示485,1表示232,0表示TTL

def get_uart_data(arg):
    print("Waiting for data on UART...")
    while True:
        # 检查串口是否有数据可读
        if uart.any():
            # 读取串口数据
            data = uart.read()
            # 打印接收到的数据
            print("Received data:", data)
            app_mqtt.update("infos",data)
        # 暂停100毫秒
        time.sleep_ms(100)


                
#开启数据上传
def get_uartdata_thread():
    _thread.start_new_thread(get_uart_data,(1,))


